import {reqCategoryListData,reqGetBannerListData,reqGetFloorListData} from '@/api'
//注册模块
const state = {
    //三级导航数据
    categoryList:[],
    //轮播图数据
    bannerList:[],
    //楼层数据
    floorsList:[],

}
const actions = {

    //获取三级数据
    async getCategoryListData(context){
        const result = await reqCategoryListData()
        if(result.code ===200) {
            //如果成功 则调用mutations中的方法，actions中调用函数只用写函数名即可
            context.commit('GET_CATEGORY_LIST_DATA',result.data)
        }else {
            console.log(result.message);
        }
    },
    //获取轮播图数据
    async getBannerListData(context){
        const result = await reqGetBannerListData()
        if(result.code ===200) {
            //如果成功 则调用mutations中的方法，actions中调用函数只用写函数名即可
            context.commit('GET_BANNER_LIST_DATA',result.data)
        }else {
            console.log(result.message);
        }
    },
    //获取floor数据
    async getFloorListData(context){
        const result = await reqGetFloorListData()
        if(result.code ===200) {
            //如果成功 则调用mutations中的方法，actions中调用函数只用写函数名即可
            context.commit('GET_FLOOR_LIST_DATA',result.data)
        }else {
            console.log(result.message);
        }
    },
}
const mutations = {
    GET_CATEGORY_LIST_DATA(state,payload) {
        // console.log(payload);
        state.categoryList = payload
    },
    GET_BANNER_LIST_DATA(state,payload) {
        // console.log(payload);
        state.bannerList = payload
    },
    GET_FLOOR_LIST_DATA(state,payload) {
        // console.log(payload);
        state.floorsList = payload
    },

}
const getters = {}
export default {
    //打开命名空间
    namespaced:true,
    state,
    actions,
    mutations,
    getters
}